package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.shop.QueryShopCategoryBo;
import com.ddwl.schema.bo.shop.ShopCategoryBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopCategoryVo;
import com.ddwl.shop.service.ShopCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 门店分类
 * @author wenbin
 * @version 1.0.0.RELEASE
 */
@Api(tags = "门店分类服务")
@RestController
public class ShopCategoryController extends BaseController {

    @Resource
    private ShopCategoryService shopCategoryService;


    @PostMapping("/createShopCategory")
    @ApiOperation("创建门店分类")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo createShopCategory(@Valid @RequestBody ShopCategoryBo bo) {
        shopCategoryService.createShopCategory(bo,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/updateShopCategory")
    @ApiOperation("修改门店分类")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo updateShopCategory(@Valid @RequestBody ShopCategoryBo bo) {
        shopCategoryService.updateShopCategory(bo,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/changeShopCategory")
    @ApiOperation("启用门店分类")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo changeShopCategory(@RequestParam String id,@RequestParam Integer effect) {
        shopCategoryService.changeShopCategory(id,effect,getUserId());
        return RestVo.ok();
    }

    @DeleteMapping("/deleteShopCategory")
    @ApiOperation("删除门店分类")
    //@Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo deleteShopCategory(@RequestParam String id) {
        shopCategoryService.deleteShopCategory(id,getUserId());
        return RestVo.ok();
    }

    @GetMapping("/getShopCategoryDetail")
    @ApiOperation("获取门店分类明细")
    public RestVo<ShopCategoryVo> detailConsolo(@RequestBody String id) {
        return RestVo.ok(shopCategoryService.getById(id));
    }

    @PostMapping("/getShopCategoryPage")
    @ApiOperation("分页查询门店分类 多典后台")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<ShopCategoryVo>> getShopCategoryPage(@Valid @RequestBody PageBo<QueryShopCategoryBo> pageBo) {
        return RestVo.ok(shopCategoryService.page(pageBo));
    }

    @PostMapping("/getShopCategoryList")
    @ApiOperation("分页查询门店分类 wbm")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE,BaseEnum.ProductEnum.FENXIAO,BaseEnum.ProductEnum.SHOP_CONSOLE,BaseEnum.ProductEnum.CONSOLE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<List<ShopCategoryVo>> getShopCategoryList(@Valid @RequestBody QueryShopCategoryBo pageBo) {
        return RestVo.ok(shopCategoryService.getShopCategoryList(pageBo));
    }

    @PostMapping("/getShopCategory")
    @ApiOperation("分页查询门店分类API")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<List<ShopCategoryVo>> getShopCategory(@RequestParam String categoryCode) {
        return RestVo.ok(shopCategoryService.getShopCategory(categoryCode));
    }
}
